<template>
  <div>
    <x-header></x-header>
    <div class="x-support">
      <x-banner :image="xsupportImage"></x-banner>
      <div class="section section-1">
        <c-page-header title="SUPPORT" subtitle="Arrival Orientation"></c-page-header>
        <div class="card">
          <div class="card--inner">
            <div class="tabs clearfix">
              <span key="{{ item.id }}" :class="{tab: true, active: item.active}"
                v-for="item in supportTabConfig" @click="toView( item.id - 1 )">
                <span class="tab__text">{{ item.tab }}</span>
                <i class="tab__pointer"></i>
              </span>
            </div>
            <div class="tabs--views">
              <transition name="fade" mode="out-in">
                <keep-alive>
                  <router-view></router-view>
                </keep-alive>
              </transition>
            </div>
          </div>

          <div class="tab-next">
            <span class="tab-next__icon" @click="tabNext()"></span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import XHeader from '@/components/XHeader'
  import XBanner from '@/components/XBanner'
  import CPageHeader from '@/components/CPageHeader'
  import { supportTabConfig } from '../config/supportTab.config'

  const tabViews = ['support_arrival', 'support_company', 'support_visa', 'support_train', 'support_work']
  const tabViewsTotal = tabViews.length

  export default {
    components: {
      CPageHeader,
      XHeader,
      XBanner
    },
    data() {
      return {
        currentIndex: 0,
        tabViews: tabViews,
        xsupportImage: require('../assets/banner/xsupport.jpg'),
        supportTabConfig
      }
    },
    methods: {
      toView(to) {
        this.currentIndex = to

        if(this.currentIndex >= 0) {
          const name = this.tabViews[this.currentIndex]
          this.$router.push({
            name
          })

          this.supportTabConfig = this.supportTabConfig.map((s, i) => {
            s.active = i === +to

            return s
          })
        }
      },
      tabNext() {
        if(this.currentIndex < tabViewsTotal - 1) {
          this.currentIndex++
        } else {
          this.currentIndex = 0
        }
        this.toView(this.currentIndex)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .tab-next {
    position: absolute;
    right: 100px;
    bottom: 76px;
  }
  .tab-next__icon {
    cursor: pointer;
    display: block;
    width: 44px;
    height: 43px;
    background: url("../assets/next_red.png") 0 0 no-repeat;
  }

  .section-1 {
    max-width: 1374px;
    margin: -326px auto 80px auto;
    font-family: Montserrat;
    .header {
      padding-left: 32px;
      padding-bottom: 30px;
    }
    .header--title {
      font-size: 70px;
      font-weight: 700;
      color: #fff;
    }
    .header--subtitle {
      font-size: 21px;
      font-family: ClanPro;
      color: #fff;
    }
    .card {
      position: relative;
      min-height: 800px;
      padding: 72px 0 92px;
      background: #fff;
      box-shadow: 0 36px 128px rgba(0,0,0,.3);
    }
    .card--inner {
      max-width: 1200px;
      margin: 0 auto;
    }
  }

  .x-support {
    .tabs {
      margin-top: -10px;
      margin-left: -30px;
    }
    .tab {
      float: left;
      padding: 0 52px 0 36px;
      text-decoration: none;
      border: 3px #231815 solid;
      position: relative;
      margin-left: 30px;
      margin-top: 10px;

      &:hover,
      &.active {
        border-color: #800000;
        background: #800000;
        .tab__text {
          color: #fff;
        }
        .tab__pointer {
          background-position: -10px 0;
        }
      }
    }
    .tab__text {
      font-size: 21px;
      color: #231815;
    }
    .tab__pointer {
      display: block;
      width: 10px;
      height: 12px;
      position: absolute;
      top: 10px;
      right: 16px;
      background: url("../assets/more-pointer.png") 0 0 no-repeat;
    }
    .tabs--views {

    }
  }

  .fade-enter-active,
  .fade-leave {
    opacity: 1;
    transition: all .3s;
  }
  .fade-enter,
  .fade-leave-active {
    opacity: 0;
    transition: all .3s;
  }
</style>
